using System.ComponentModel;
using System.Globalization;
using System.Reflection;
using Meebey.SmartIrc4net;

namespace Thunder.Irc.Parser.Default
{
    /// <summary>
    /// Handles the Join message 
    /// </summary>
    internal class MessageParserCtcpRequest : MessageParser
    {
        /// <summary>
        /// Gets the type of message handled by the parser
        /// </summary>
        public override ReceiveType MessageType
        {
            get { return ReceiveType.CtcpRequest; }
        }

        /// <summary>
        /// This method is invoked during message parsing.
        /// </summary>
        /// <param name="args">The <see cref="CancelMessageProcessingEventArgs"/> containing the message to be passed</param>
        /// <remarks>You can cancel further processing of the message by setting the <see cref="CancelEventArgs.Cancel"/> to true</remarks>
        protected override void ParseCore(CancelMessageProcessingEventArgs args)
        {
            string message = args.MessageData.Message.Trim((char)1).ToLowerInvariant();

            switch (message)
            {
                case "version":
                    this.Manager.WriteStatus(string.Format(CultureInfo.CurrentCulture, Localized.CtcpReceived, "Version"), ReceiveType.CtcpRequest);
                    this.Manager.IrcClient.CtcpVersion = string.Format(CultureInfo.InvariantCulture, "{0} {1} for {2}", Assembly.GetExecutingAssembly().AssemblyProduct(), Assembly.GetEntryAssembly().GetName().Version, NonLocalized.Windows);
                    this.Manager.IrcClient.SendReply(args.MessageData, string.Format(CultureInfo.InvariantCulture, "{0}VERSION {1}:{2}:{3}{0}", (char)1, Assembly.GetExecutingAssembly().AssemblyProduct(), Assembly.GetEntryAssembly().GetName().Version, NonLocalized.Windows));
                    break;

                default:
                    this.Manager.WriteStatus(string.Format(CultureInfo.CurrentCulture, Localized.CtcpUnknown, args.MessageData.Message), ReceiveType.CtcpRequest);
                    break;
            }
        }
    }
}